
package com.wwy.monitor.controller;

import com.wwy.monitor.common.MessageException;
import com.wwy.monitor.common.ServiceResponse;
import com.wwy.monitor.model.tddl.query.MonitorCaseQuery;
import com.wwy.monitor.model.vo.MonitorCaseBatchVO;
import com.wwy.monitor.service.MonitorCaseService;
import com.wwy.monitor.util.OneLogUtil;
import com.wwy.monitor.util.UserUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping(value = "/api/monitorCase")
public class MonitorCaseController {
    @Resource
    private MonitorCaseService monitorCaseService;

    /**
     * 分页查询case任务
     */
    @GetMapping("/page")
    @ResponseBody
    private ServiceResponse page(MonitorCaseQuery param, HttpServletRequest request) throws IOException, ServletException {
        OneLogUtil.getOpLog("/api/monitorCase/page", "case查询", request);
        String empId = UserUtils.getBucEmpId(request);
        param.setCreateUser(empId);
        return ServiceResponse.success(monitorCaseService.queryMonitorCase(param));
    }

    @PostMapping("/add")
    private ServiceResponse add(@RequestBody MonitorCaseBatchVO dto, HttpServletRequest request) throws IOException, ServletException {
        String empId = UserUtils.getBucEmpId(request);
        dto.setCreateUser(empId);
        return ServiceResponse.success(monitorCaseService.addMonitorCase(dto));
    }

    @GetMapping("/caseLogs")
    private ServiceResponse caseLogs(Long taskId) {
        if (null == taskId || taskId <= 0) {
            throw new MessageException("非法id");
        }
        return ServiceResponse.success(monitorCaseService.queryCaseTaskLog(taskId));
    }

    /**
     * 逻辑删除case任务
     */
    @PostMapping("{id}/delete")
    public ServiceResponse delete(@PathVariable Long id) {
        return ServiceResponse.success(monitorCaseService.deleteById(id));
    }
}